package com.think.oauth.user.constant;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public enum ResultCode {
	/* 成功状态码 */
	SUCCESS(10000, "成功"),

	/* 参数错误：10001-19999 */
	PARAM_IS_INVALID(10001, "参数无效"),
	PARAM_IS_BLANK(10002, "参数为空"),
	PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
	PARAM_NOT_COMPLETE(10004, "参数缺失"),
	PARAM_TOKEN_MISS(10005,"缺少Token"),
	PARAM_TOKEN_EXPIRED(10006,"登陆已过期，请重新登陆！"),
	PARM_EMAIL_CODE_INVALID(10007, "邮箱验证码错误或验证码过期"),

	/* 用户错误：20001-29999*/
	USER_NOT_LOGGED_IN(20001, "用户未登录"),
	USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
	USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
	USER_NOT_EXIST(20004, "用户不存在"),
	USER_INFO_NOT_FOUND(20006,"用户信息不存在"),
	USER_NOT_INIT(20007,"用户信息没有初始化"),
	USER_HAS_EXISTED(20005, "用户已存在"),
	USER_DATA_FILE_EMPTY(20006, "文件为空"),
	USER_DATA_DUPLICICATE(20007, "用户名或邮箱已经存在!"),
	USER_PASSWOR_ERROR(20008, "用户密码错误!"),
	USER_NAME_NOT_FOUND(20009, "用户名没有找到!"),
	USER_EMAIL_NOT_FOUND(200010, "用户邮箱没有找到!"),
	USER_EMAIL_NAME_NOT_PAIR(200011, "用户名和邮箱不匹配!!"),
	/* 业务错误：30001-39999 */
	SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"),
	SPECIFIED_PERMISSION_NAME_INVALID(30002, "权限名非法"),

	/* 系统错误：40001-49999 */
	SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),
	API_NOT_IMPLEMENT(40002,"接口暂未实现"),
	CLIENT_ALREADY_EXITS(40003,"client已经存在"),
	CLIENT_NOT_EXITS(40004,"client不存在"),
	/* 数据错误：50001-599999 */
	RESULE_DATA_NONE(50001, "数据未找到"),
	DATA_IS_WRONG(50002, "数据有误"),
	DATA_ALREADY_EXISTED(50003, "数据已存在"),
	COURSE_NOT_EXIST(50004,"课程不存在"),
	DATE_IS_WRONG(50005,"日期格式错误"),
	RECORD_NOT_EXIST(50006,"记录不存在"),
	STORE_NOT_EXIST(50007,"收藏不存在"),
	EXAM_NOT_EXIST(50008,"考试不存在"),
	EXAM_RULE_NOT_EXIST(50009,"考試規則不存在"),
	SUBJECT_ALREADY_EXIST(50010,"科目已存在"),
	SUBJECT_NOT_EXIST(50011,"科目不存在"),
	TITLE_NOT_EXIST(50012,"试题不存在"),
	NEWS_NOT_EXIST(50013,"新闻不存在"),
	NEWSTYPEID_NOT_EXIST(50014,"新闻类型不存在"),
	NEWSTIME_NOT_EXIST(50015,"新闻时间限制不存在"),
	NEWS_STORED_NOT_EXIST(50016,"新闻收藏不存在"),
	USERACTION_NOT_EXIST(50017,"用户行为信息不存在"),
	NEWSLIMIT_NOT_EXIST(50018,"新闻权限不存在"),
	RECORD_TODAY_FULL(50019,"今天记录已经完成"),
	INTEVAL_TOO_SMALL(50020,"间隔时间太短，稍后再试"),

	/* 接口错误：60001-69999 */
	INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
	INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
	INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
	INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
	INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
	INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),

	/* 权限错误：70001-79999 */
	PERMISSION_NO_ACCESS(70001, "无访问权限");



	private Integer code;

	private String message;

	ResultCode(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public Integer code() {
		return this.code;
	}

	public String message() {
		return this.message;
	}

	public static String getMessage(String name) {
		for (ResultCode item : ResultCode.values()) {
			if (item.name().equals(name)) {
				return item.message;
			}
		}
		return name;
	}

	public static Integer getCode(String name) {
		for (ResultCode item : ResultCode.values()) {
			if (item.name().equals(name)) {
				return item.code;
			}
		}
		return null;
	}

	@Override
	public String toString() {
		return this.name();
	}

	//校验重复的code值
	public static void main(String[] args) {
		ResultCode[] ApiResultCodes = ResultCode.values();
		List<Integer> codeList = new ArrayList<Integer>();
		for (ResultCode ApiResultCode : ApiResultCodes) {
			if (codeList.contains(ApiResultCode.code)) {
				System.out.println(ApiResultCode.code);
			} else {
				codeList.add(ApiResultCode.code());
			}
		}
	}
}

